package info.ask4research.dao.impl;

import info.ask4research.dao.IActivityDAO;
import info.ask4research.dao.IAddonDAO;
import info.ask4research.dao.core.impl.AbstractDaoImpl;
import info.ask4research.model.activities.Activity;
import info.ask4research.model.addons.Addon;
import info.ask4research.model.addons.MultipleChoice;
import info.ask4research.model.addons.QuestionsAndAnswers;
import info.ask4research.model.addons.TextWork;
import info.ask4research.model.addons.UploadingFiles;
import info.ask4research.model.roles.Role;

import java.util.List;

import org.hibernate.SessionFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.orm.hibernate3.HibernateTemplate;
import org.springframework.stereotype.Repository;

@Repository("activityDAO")
public class ActivityDAO extends AbstractDaoImpl<Activity> implements IActivityDAO {

	public ActivityDAO() {
		super(Activity.class);
	}
	
	private HibernateTemplate hibernateTemplate;

	@Autowired
	public void setSessionFactory(SessionFactory sessionFactory) {
		hibernateTemplate = new HibernateTemplate(sessionFactory);
	}

	@Override
	public Activity getbyGraphId(String activityId) {
		List<Activity> activities = hibernateTemplate.find("from Activity activity where activity.activityGraphId=?",  activityId);
		if(!activities.isEmpty()){
			return activities.get(0);
		}else{
			return null;
		}
		
	}

	public Activity getbyGraphIdAndUoLId(String activityId, Integer id) {
		List<Activity> activities = hibernateTemplate.find("from Activity activity where activity.activityGraphId=? and activity.unitOfLearning.id=?",  activityId, id);
		if(!activities.isEmpty()){
			return activities.get(0);
		}else{
			return null;
		}
	}
}
